import { InjectionToken } from "tsyringe";
import { IApp, INotificationListener, IToastListener } from "../core/app";
import { tryGetAll } from "../utils/tryGetAll";
import { tryGet } from "../utils/tryGet";
import { IScriptManager } from "../core/scriptManager";

export const NOTIFICATION_LISTENER: InjectionToken<INotificationListener> = `NOTIFICATION_LISTENER`
export const TOAST_LISTENER: InjectionToken<IToastListener> = `TOAST_LISTENER`
export const APP: InjectionToken<IApp> = `APP`

export const CURRENT_ACTIVITY: InjectionToken<string> = `CURRENT_ACTIVITY`
export const CURRENT_PACKAGE: InjectionToken<string> = `CURRENT_PACKAGE`
export const CURRENT_TASK: InjectionToken<string> = `CURRENT_TASK`

export const STATE_CHANGE: InjectionToken<any> = `STATE_CHANGE`
export const WS_CONNECT: InjectionToken<any> = `WS_CONNECT`
export const WS_CONNECT_CLOSE: InjectionToken<any> = `WS_CONNECT_CLOSE`
export const SCRIPT_MANAGER: InjectionToken<IScriptManager> = `SCRIPT_MANAGER`

export const DEVICE_SETTING: InjectionToken<any> = `DEVICE_SETTING`

export const getScriptManager = () => {
    return tryGet(CURRENT_TASK)
}

export const getDeviceSetting = () => {
    return tryGet(CURRENT_TASK)
}

export const getCurrentTask = () => {
    return tryGet(CURRENT_TASK)
}

// 快手包名
export const KWAI_PACKAGE: string = `com.smile.gifmaker`


export function getCurrentActivity() {
    return tryGet(CURRENT_ACTIVITY)
}

export function getCurrentPackage() {
    return tryGet(CURRENT_PACKAGE)
}

export function currentPackageIs(name: string) {
    return getCurrentPackage() === name;
}

export function currentPackageIn(names: string[]) {
    return names.includes(getCurrentPackage())
}

export function currentActivityIs(name: string) {
    return getCurrentActivity() === name;
}

export function currentActivityIn(names: string[]) {
    return names.includes(getCurrentActivity());
}
export const getApps = (): IApp[] => {
    return tryGetAll(APP)
}

export const getNotificationListeners = (): INotificationListener[] => {
    return tryGetAll(NOTIFICATION_LISTENER)
}


export const getToastListeners = (): IToastListener[] => {
    return tryGetAll(TOAST_LISTENER)
}
